
#ifndef KRAWD3D9MESHMATERIAL_H
#define KRAWD3D9MESHMATERIAL_H

#include "kraw/krawd3d9material.h"

class nD3D9Material;
class Kraw3DModel;

struct IDirect3DVertexDeclaration9;

class KrawD3D9MeshMaterial : public KrawD3D9Material
{
public:

    enum
    {
        Invalid = 0,
        Position,
        Normal,
        TexCoord0,
        TexCoord1,
        TexCoord2,
        TexCoord3,
        Color,
        Tangent,
        Binormal,
        Weights,
        JIndices,

        MaxStreams,
    };

    //initialize material
    KrawD3D9MeshMaterial();
    ~KrawD3D9MeshMaterial();

    virtual bool Init();
    virtual void Destroy();

    //geometry loading
    virtual void* Load( Kraw3DModel* );
    virtual void Unload( void* pModelData );
    virtual void Render( void* pModelData );

    //geometry declaration
    void DeclareStream( uint, uint );

protected:

    bool InitVertexDeclaration();

    bool ExportVertices( Kraw3DModel*, uint&, float*& );
    bool ExportIndices( Kraw3DModel*, uint*& );
    void Delete( float*, uint* );

    void UpdateTransform();

    struct Stream
    {
        uint type;
        uint size;
    };

    nArray<Stream> streams;
    uint vertexSize;

    void* pVertexDecl;
};

#endif /*KRAWD3D9MESHMATERIAL_H*/
